package com.example.shopping.dao;

import com.example.shopping.pojo.ContentCategory;
import com.example.shopping.pojo.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/

//广告类型管理
@Repository
public interface IContentCategoryDao {

    @Select("select * from content_category")
    @Results(value = {
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "content", many = @Many(select = "com.example.shopping.dao.IContentDao.selectContentById", fetchType = FetchType.EAGER))
    })
    List<ContentCategory> selectContentCategory();


    @Delete("delete from content_category where id =#{id}")
    int deleteContentCategoryById(int id);

    @Insert("insert into content_category(id,name,status) values(null,#{name},#{status})")
    int insertContentCategory(ContentCategory contentCategory);

    @Select("select * from content_category where name like #{name}")
    @Results(value = {
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "content", many = @Many(select = "com.example.shopping.dao.IContentDao.selectContentById", fetchType = FetchType.EAGER))
    })
    List<ContentCategory> selectContentCategoryByName(String name);

    //修改为开启状态
    @Update("update content_category set status=1 where id =#{id}")
    int updateContentCategoryStatusOpen(int id);

    //修改为关闭状态
    @Update("update content_category set status=2 where id =#{id}")
    int updateContentCategoryStatusClose(int id);

}
